package game;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import level.LevelDownloader;

/**
 * 
 * @author Jevgeni Krutov
 *
 */
public class Menu extends JFrame {
	private static final long serialVersionUID = -2135190122896866375L;

	public Menu() {
		JPanel panel = new JPanel();
		getContentPane().add(panel);

		panel.setLayout(null);

		List<String> levels = LevelDownloader.getLevelList();
		
		int i = 0;
		for(final String level : levels) {
			JButton buttonForClient = new JButton();
			JButton buttonForServer = new JButton();
			
			buttonForClient.setText("client: " + level.substring(0, level.length()/*-4*/));
			buttonForServer.setText("server: " + level.substring(0, level.length()/*-4*/));
			
			buttonForClient.setBounds(10, 10 + 25*i, 270, 20);
			buttonForServer.setBounds(300, 10 + 25*i++, 270, 20);
			
			buttonForClient.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent event) {
					new Game(level, false);
					System.exit(0);
				}
			});
			buttonForServer.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent event) {
					new Game(level, true);
					System.exit(0);
				}
			});
			panel.add(buttonForClient);
			panel.add(buttonForServer);
		}

		setTitle("List of levels");
		setSize(580, 700);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
	}

	public static void main(String[] args) {
	  	new Menu();
    }
}